package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.LotteryRecords;
import com.yfp.operation.domain.dto.GrantRepertoryDTO;
import com.yfp.operation.domain.dto.LotteryListDTO;
import com.yfp.operation.domain.dto.participationInfoDTO;
import com.yfp.operation.domain.vo.*;
import com.yfp.operation.service.LotteryRecordsService;
import com.yfp.operation.domain.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @version 1.0
 * @date 2024-12-30 10:09
 */
@RestController
@RequestMapping("/lottery")
@Tag(name = "pc-抽奖")
@Slf4j
public class LotteryController extends BaseController {


    @Resource
    private LotteryRecordsService lotteryRecordsService;



    @PostMapping("/addLottery")
    @Operation(summary = "新增抽奖活动")
    public R<?> addLottery(@RequestBody LotteryRecords lotteryRecords){
        log.info("参数:{}",lotteryRecords);
        lotteryRecordsService.addLottery(lotteryRecords);
        return R.ok();
    }


    @GetMapping("/lotteryList")
    @Operation(summary = "抽奖活动列表")
    public R<TableDataInfo<LotteryListVO>> lotteryList(LotteryListDTO lotteryListDTO) {
        log.info("参数:{}",lotteryListDTO);
        startPage();
        List<LotteryListVO> list = lotteryRecordsService.lotteryList(lotteryListDTO);
        TableDataInfo dataTable = getDataTable(list);
        List<LotteryListVO> lotteryListVOList = lotteryRecordsService.lotteryListComplement(list);
        dataTable.setRows(lotteryListVOList);
        return R.ok(dataTable);
    }


    @GetMapping("/participation")
    @Operation(summary = "参与人数")
    public R<TableDataInfo<ParticipationVO>> participationInfo(participationInfoDTO participationInfoDTO){
        log.info("参数:{}",participationInfoDTO);
        startPage();
        List<ParticipationVO> list = lotteryRecordsService.participation(participationInfoDTO);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    @GetMapping("/prizeList")
    @Operation(summary = "领取奖励列表")
    public R<TableDataInfo<PrizeListVO>> prizeList(@RequestParam("clientId") String clientId , @RequestParam("lotteryId") Long lotteryId){
        log.info("参数clientId:{},,,lotteryId:{}",clientId,lotteryId);
        startPage();
        return R.ok(getDataTable(lotteryRecordsService.prizeList(clientId,lotteryId)));
    }


    @GetMapping("/participationInfo")
    @Operation(summary = "参与详情")
    public R<ParticipationInfoVO> participationInfo(@RequestParam("lotteryId") Long lotteryId, @Param("positionName") String positionName){
        return R.ok(lotteryRecordsService.participationInfo(lotteryId,positionName));
    }


    @GetMapping("/participationPositionData")
    @Operation(summary = "参与点位数据")
    public R<TableDataInfo<participationPositionDataVO>> participationPositionData(@RequestParam("lotteryId") Long lotteryId, @Param("positionName") String positionName){
        startPage();
        List<participationPositionDataVO> list = lotteryRecordsService.participationPositionData(lotteryId,positionName);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    @GetMapping("/grantRepertory")
    @Operation(summary = "库存发放详情")
    public R<TableDataInfo<PrizeVO>> grantRepertory(GrantRepertoryDTO grantRepertoryDTO){
        log.info("参数:{}",grantRepertoryDTO);
        startPage();
        List<PrizeVO> list = lotteryRecordsService.grantRepertory(grantRepertoryDTO);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    @GetMapping("/{id}")
    @Operation(summary = "根据id获取抽奖活动")
    public R<LotteryRecords> getById(@PathVariable("id") Long id){
        return R.ok(lotteryRecordsService.selectById(id));
    }


    @PutMapping
    @Operation(summary = "修改抽奖活动")
    public R<?> updateLottery(@RequestBody LotteryRecords lotteryRecords){
        log.info("参数:{}",lotteryRecords);
        lotteryRecordsService.updateLottery(lotteryRecords);
        return R.ok();
    }


    @PostMapping("/lotteryCount")
    @Operation(summary = "增加抽奖次数")
    public R<Void> lotteryCount(@RequestParam("clientId") String clientId, @RequestParam("price") String price ,@RequestParam("cityName") String cityName) {
        lotteryRecordsService.lotteryCount(clientId, price, cityName);
        return R.ok();
    }


    @GetMapping("/isUnderway")
    @Operation(summary = "校验是否存在进行中的活动  true可以建")
    public R<Boolean> isUnderway(@RequestParam("cityName") String cityName){
        return R.ok(lotteryRecordsService.isUnderway(cityName));
    }




}
